package com.wz.project.bas.trayCodeHead.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.trayCodeHead.domain.BasTraycodeHead;
import com.wz.project.bas.trayCodeHead.service.IBasTraycodeHeadService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 托盘条码头部Controller
 * 
 * @author wz
 * @date 2021-11-22
 */
@Controller
@RequestMapping("/bas/trayCodeHead")
public class BasTraycodeHeadController extends BaseController
{
    private String prefix = "bas/trayCodeHead";

    @Autowired
    private IBasTraycodeHeadService basTraycodeHeadService;

    @RequiresPermissions("bas:trayCodeHead:view")
    @GetMapping()
    public String trayCodeHead()
    {
        return prefix + "/trayCodeHead";
    }

    /**
     * 查询托盘条码头部列表
     */
//    @RequiresPermissions("bas:trayCodeHead:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasTraycodeHead basTraycodeHead)
    {
        startPage();
        List<BasTraycodeHead> list = basTraycodeHeadService.selectBasTraycodeHeadList(basTraycodeHead);
        return getDataTable(list);
    }

    /**
     * 导出托盘条码头部列表
     */
    @RequiresPermissions("bas:trayCodeHead:export")
    @Log(title = "托盘条码头部", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasTraycodeHead basTraycodeHead)
    {
        List<BasTraycodeHead> list = basTraycodeHeadService.selectBasTraycodeHeadList(basTraycodeHead);
        ExcelUtil<BasTraycodeHead> util = new ExcelUtil<BasTraycodeHead>(BasTraycodeHead.class);
        return util.exportExcel(list, "trayCodeHead");
    }

    /**
     * 新增托盘条码头部
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存托盘条码头部
     */
    @RequiresPermissions("bas:trayCodeHead:add")
    @Log(title = "托盘条码头部", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasTraycodeHead basTraycodeHead)
    {
        return toAjax(basTraycodeHeadService.insertBasTraycodeHead(basTraycodeHead));
    }

    /**
     * 修改托盘条码头部
     */
    @GetMapping("/edit/{tHead}")
    public String edit(@PathVariable("tHead") String tHead, ModelMap mmap)
    {
        BasTraycodeHead basTraycodeHead = basTraycodeHeadService.selectBasTraycodeHeadById(tHead);
        mmap.put("basTraycodeHead", basTraycodeHead);
        return prefix + "/edit";
    }

    /**
     * 修改保存托盘条码头部
     */
    @RequiresPermissions("bas:trayCodeHead:edit")
    @Log(title = "托盘条码头部", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasTraycodeHead basTraycodeHead)
    {
        return toAjax(basTraycodeHeadService.updateBasTraycodeHead(basTraycodeHead));
    }

    /**
     * 删除托盘条码头部
     */
    @RequiresPermissions("bas:trayCodeHead:remove")
    @Log(title = "托盘条码头部", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basTraycodeHeadService.deleteBasTraycodeHeadByIds(ids));
    }
}
